import os
import json

def fileDirOption(path):           # 文件夹创建
    # path = path.replace('?', '？').replace(':', '_') # Windows文件名禁用符号 👉 \/:*?"<>| 👈
    isExists=os.path.exists(path)
    try:
        if not isExists:
            os.makedirs(path)
            # print(path+' 创建成功')
            return True
        else:
            # 如果目录存在则不创建，并提示目录已存在
            # print(path+' 目录已存在')
            return True
    except Exception as e:
        print(path,e)
        return False

def get_files_list(user_name):
    return_files = []
    for root,dirs,files in os.walk(f"sql/datafiles/{user_name}"):
        print(root,dirs,files)
        return_files = files
    return return_files

def read_file(user_name, file_name):
    # if file_name.endswith(".json"):
    with open(f'sql/datafiles/{user_name}/{file_name}', 'r' ,encoding="utf-8") as f:
        load_dict = json.load(f)
    return load_dict

def remove_file(user_name, file_name):
    os.remove(f"sql/datafiles/{user_name}/{file_name}")
    return True
